<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link href="../../static/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../../static/vui/css/vui.css">

    <script type="text/javascript" src="../../static/js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../../static/layer/layer.js"></script>
    <script type="text/javascript" src="../../static/vui/js/vui.js"></script>
    <script type="text/javascript" src="../../static/vui/js/treegrid.js"></script>
    <script type="text/javascript" src="../../static/js/common.js"></script>
</head>
<body>

    <div id="table"></div>

<script>
    var params = app.getRequestParams();
    $(function(){
        $('#table').treegrid({
            url:app.BASE_API_URL+'productType/select',
            columns:[
                {field:'name',title:'商品分类',width:150,formatter:function (row) {
                    var txt = row.name.substr(row.name.lastIndexOf('/')+1);
                    return '<a href="javascript:void(0);" onclick="selectRow(this)" class="link">'+txt+'</a>';
                }}
            ]
        });
    });

    function getOpenFrame(){
        if( params.index == -1 ){
            //当前页
            return parent;
        }else{
            //当前页的弹出页
            return parent.frames[0];
        }
    }

    function selectRow(_this) {
        var row = $(_this).parent().parent().parent().parent().data();
        var search = getOpenFrame().$('#'+params.searchId);
        search.search('setValue',row[params.idField],row.name);
        app.closeLastWindow();
    }

</script>
</body>
</html>